package com.sunzm.flink.datastream.java.operator;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class JavaUnionDemo {
    private static boolean isLocal = true;

    public static void main(String[] args) throws Exception {

        //获取执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        if (isLocal) {
            env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());
        }

        DataStreamSource<Integer> ds1 = env.fromElements(1, 3, 5);
        DataStreamSource<Integer> ds2 = env.fromElements(2, 4, 6);
        DataStream<Integer> unionDataStream  = ds1.union(ds2);

        unionDataStream.print();

        //启动程序
        String className = Thread.currentThread().getStackTrace()[1].getClassName();
        String simpleName = className.substring(className.lastIndexOf(".") + 1);
        env.execute(simpleName);
    }
}
